<head>
	<link rel="stylesheet" type="text/css" href="profile_inner.css" />
</head>

<img src="/img/icons/back.gif"><a href="frame.php?page=profile"> Return to profile </a>

<div class="padded_text">

<div class="head">Your Inbox</div>

<p /><img src="/img/arrow_green.gif"><a href="frame.php?page=composemessage">Compose new message</a>

<p />

	<div>
		<table class="inboxmsg_head">
			<tr>
				<td width="120px">From</td>
				<td width="260px">Subject</td>
				<td width="120px">Received</td>
			</tr>
		</table>
	</div>

<?php

	error_reporting(0);
	session_start();
	error_reporting(1);

	require_once "../common/PinSQL.obj";
	$pinSQL = new PinSQL();
	
	$username = $_SESSION['username'];
	
	$pinSQL->Query("SELECT * FROM messages WHERE touser='$username' AND archived='0' ORDER BY date DESC");
	
 	if ( $pinSQL->GetNumRows() )
 	{
	 	// user has messages
	 	
		while ( $row = $pinSQL->FetchNextRow() )
		{
			
			$prettydate = date(  'M j', strtotime( $row['date'] )  );
	  		$prettytime = date(  'g:ia', strtotime( $row['date'] )  );
	  		
			if (!$row['isread'])
			{
				// unread message
				
?>

	<div>
		<table class="inboxmsg_unread">
	
<?php
				
			} else {
				// read message
				
?>

	<div>
		<table class="inboxmsg_read">
	
<?php

			}
			
?>

			<tr>
				<td width="120px"><?php echo $pinSQL->GetFullName($row['fromuser']); ?></td>
				<td width="275px"><?php 
				
			if (!$row['isread'])
			{
				echo '<img src="/img/icons/new_message.gif">';
			}
				
				?><a href="frame.php?page=showmessage&id=<?php echo $row['id'] ?>"> <?php echo ($row['subject']) ? $row['subject'] : "[no subject]"; ?> </a></td>
				<td width="125px"><?php echo $prettydate. ", " . $prettytime; ?></td>
				<td width="50px">
				<small><small><a href="deletemessage.php?mode=inbox&id=<?php echo $row['id'] ?>">Delete</a></small></small></td>
			</tr>
		</table>
	</div>

<?php
			
		}
	 	
	} else {
		
?>

	Your inbox is currently empty.

<?php
		// user has no messages
 	}

?>

</div>
